package com.bdqn.controller;

import com.bdqn.pojo.Menu;
import com.bdqn.service.MenuService;
import com.bdqn.util.TokenUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    MenuService menuService;
    @Autowired
    TokenUtil tokenUtil;
    /**
     * 获取用户所有的菜单权限
     */
    @GetMapping("getUserMenus")
    public List<Menu> getUserMenus(@RequestHeader("token")String token){
        //解析token，获取用户编号
        int uid = tokenUtil.getUid(token);
        List<Menu> list=menuService.getUserMenus(uid);
        return list;
    }
    /**
     * 获取所有的菜单,按照层次关系返回
     */
    @GetMapping("getMenus")
    public List<Menu> getMenus(){
        List<Menu> list=menuService.getMenusAll();
        return list;
    }
    @GetMapping("getPageMenu")
    public PageInfo<Menu> getMenu(int pageNum, int pageSize, String mname){
        PageInfo<Menu> menuPageInfo = menuService.selectPage(pageNum, pageSize, mname);
        return menuPageInfo;
    }

}
